/*
	Simple Software Renderer (SSRenderer)
	Copyright (C) 2007 Piotr Orzechowski <piotr.orzechowski@gmail.com>

	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#ifndef _HPTIMER_H
#define _HPTIMER_H

#if defined(WIN32)
	#define WIN32_LEAN_AND_MEAN
	#include <windows.h>
#else
	#include <sys/time.h>
#endif

namespace util
{

/**
	HPTimer stands for High Performance Timer and utilizes the best
	frequency timing for the given platform.
*/
class HPTimer
{
public:

	HPTimer()
	{
		m_bInitialized = false;
	}

	virtual ~HPTimer()
	{
		Deinitialize();
	}

	/**
		Initializes the HPTimer.

		@return true if initialization was successful, false otherwise
	*/
	bool Initialize();

	/**
		Deinitializes the HPTimer.
	*/
	void Deinitialize();

	/**
		Returns time (seconds) elapsed since HPTimer initialization.

		@return time sample
	*/
	float GetElapsedSeconds();

protected:

	bool m_bInitialized;

#ifdef WIN32

	// For Win32 we use QueryPerformanceTimer

	LARGE_INTEGER   m_StartTime;
	LARGE_INTEGER   m_TicksPerSecond;

#else

	unsigned long	m_StartTime;

#endif

private:

	HPTimer(HPTimer&) {}
	HPTimer& operator=(HPTimer&) { return *this; }
};

} // namespace

#endif
